package com.tust.app.dao;



import com.tust.app.domain.Answer;
import com.tust.app.domain.Topic;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public interface TopicMapper {

    // 模拟数据库操作

    @Select("select * from t_topic ")
     List<Topic> findAllTopics();

    @Select("select * from t_topic where id = #{id}")
    Topic findById(int id);

    @Insert("insert into t_topic (id, title, detail,pubtime,edituser) values (#{id}, #{title}, #{detail},#{pubtime},#{edituser})")
     void save(Topic topic);


    @Delete("delete from t_topic where id = #{id}")
     void deleteById(int id);

    @Update("update t_topic set state = #{state} where id = #{id}")
    void update(@Param("state") int state, @Param("id")  int id);


    @Select("select * from t_answer where topicId=#{topicId} ")
    List<Answer> getAnswerList(@Param("topicId") int topicId);

    @Insert("insert into t_topic (title,pubtime,detail,edituser) values (#{title},#{pubtime},#{detail},#{edituser} )" )
    void addTopic(@Param("edituser")  String edituser, @Param("title") String title,@Param("detail")  String detail,@Param("pubtime")  String pubtime);
    @Select("select * from t_topic where edituser=#{edituser}")
    List<Topic> getAllTopicsByUser(@Param("edituser") String edituser);

    @Update("update t_topic set title=#{title},detail=#{detail} where id=#{id}")
    void updateTopic(@Param("id")int id, @Param("title")String title, @Param("detail")String detail);

    @Select("select * from t_topic where id=#{id}")
    Topic getTopicById(@Param("id") int id);
}
